<html>
<head>
<title>COM Interface</title>
<link rel="stylesheet" type="text/css" href="Styles.css">

<script language="javascript">

  var H2ViewerSvr = null;

  //-----------------------------------------------------
  // Return MS IE major version number
  // Return 0 for non-IE browser
  //-----------------------------------------------------
  function msieversion() {
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE ");
    if (msie > 0)
       return(parseInt(ua.substring(msie+5,ua.indexOf(".", msie))));
    return(0);  // is non-MS browser
  }

//Show Error if not IE5 or above  
if (msieversion() <= 4)
   window.alert('Error: This page requires Internet Explorer 5.0 or greater');

      
  //------------------------------------------------------------------
  //Connect to the H2Viewer.EXE Server
  //------------------------------------------------------------------
  function ConnectToH2Viewer() {
    try {
      if (H2ViewerSvr == null) 
        H2ViewerSvr = new ActiveXObject("H2Viewer.h2vmain");
    }
    catch(e){
      window.alert(e.name + ":: " + e.message + "\n\n"
        + 'H2Viewer.EXE Server not installed or not correctly registered.\nTip: Simply run H2Viewer.exe once to register it as a ActiveX Server');
    }
    if (H2ViewerSvr) {
      //10-Jul-2004: Poll WindowHandle until != 0 to ensure main window initialized 
      //Fixes a bug where Window is not available when immediately calling ShowWindow
      do {} while (H2ViewerSvr.WindowHandle == 0); 
      return(1);    //connected
      }
    else
      return(0);    //not connected
  }


  //Connect and immediately Show. 
  function ConnectToH2ViewerAndShow() {
    if (ConnectToH2Viewer() == 1)
      H2ViewerSvr.ShowWindow = 1;
  }
    

  // -- Check Connect --
  function IsConnected(NoShowError) {
    try {
      if ((H2ViewerSvr) && (H2ViewerSvr.Version))  //Test the connection
        retval = 1;        //connected
      else 
        retval = 0;        //not connected
    }
    catch(e) {
      retval = 0;          //not connected
    }    
    if (retval == 0) {
      if (typeof(NoShowError) == "undefined") 
        window.alert('Please Connect to the H2Viewer COM Server.');
      H2ViewerSvr = null;  
    }  
    //Also check the busy state 
//    if ((retval == 1) && (FH2View.Busy != 0)) {
//      retval = -1;        //Busy
//      window.alert('Check the Busy flag before calling.');
//      }
    return(retval);  
  }

  // -- Method: Close() --
  function CloseH2Viewer() {
    if (IsConnected() == 1)
      H2ViewerSvr.Close();
    if (IsConnected("NoErrorMessage") == 0)
      H2ViewerSvr = null;
  }

  // -- Property: ShowWindow = [0/1] --
  function ShowWindow(value) {
    if (IsConnected() == 1)
      H2ViewerSvr.ShowWindow = value;
  }

  // -- Property: Version --
  function GetVersion() {
    if (IsConnected() == 1)
      window.alert(H2ViewerSvr.Version);
  }

  // -- Property: V1, V2, V3, V4 --
  function GetVersionNos() {
    if (IsConnected() == 1)
      window.alert("V1=" + H2ViewerSvr.V1 + "\nV2=" + H2ViewerSvr.V2 + "\nV3=" + H2ViewerSvr.V3 + "\nV4=" + H2ViewerSvr.V4);
  }
  
  // -- Property: WindowHandle --
  function GetWindowHandle() {
    if (IsConnected() == 1)
      window.alert("Main WindowHandle = " + H2ViewerSvr.WindowHandle);
  }
  
  // -- Property: URL (Set) --
  function SetURL() {
    if (IsConnected() == 1)
      H2ViewerSvr.URL = document.all.ID_URLCtrl.value;
  } 

  // -- Property: URL (Get) --
  function GetURL() {
    if (IsConnected() == 1)
      document.all.ID_URLCtrl.value = H2ViewerSvr.URL;
  }


  // -- Property: CurrentNS (Get) --
  function GetCurrentNS() {
    if (IsConnected() == 1)
      window.alert("CurrentNS = " + H2ViewerSvr.CurrentNS);
  }

  // -- Function: Open(URL, Filter) --
  function DoOpenURLFilter() {
    if (IsConnected() == 1)
      H2ViewerSvr.Open(document.all.ID_OpenURL.value, document.all.ID_OpenFilterName.value, document.all.ID_OpenFilterQuery.value);
  }

  // -- Property: FilterName (Set) --
  function SetFilterName() {
    if (IsConnected() == 1)
      H2ViewerSvr.FilterName = document.all.ID_FilterName.value;
  }

  // -- Property: FilterName (Get) --
  function GetFilterName() {
    if (IsConnected() == 1)
      document.all.ID_FilterName.value = H2ViewerSvr.FilterName;
  }

  // -- Property: FilterQuery (Set) --
  function SetFilterQuery() {
    if (IsConnected() == 1)
      H2ViewerSvr.FilterQuery = document.all.ID_FilterQuery.value;
  }

  // -- Property: FilterQuery (Get) --
  function GetFilterQuery() {
    if (IsConnected() == 1)
      document.all.ID_FilterQuery.value = H2ViewerSvr.FilterQuery;
  }

  // -- Function: QueryForURL(P1, P2, P3, P4, P5) --
  function DoQueryForURL() {
    if (IsConnected() == 1) {
      var ss = H2ViewerSvr.QueryForURL(document.all.ID_QueryP1.value, document.all.ID_QueryP2.value, document.all.ID_QueryP3.value, document.all.ID_QueryP4.value, document.all.ID_QueryP5.value);
      if (ss == "")
        window.alert('No Result');
      else { 
        if (window.prompt("Result Found. Click OK to display the Topic", ss)) {
          H2ViewerSvr.ShowWindow = 1;
          H2ViewerSvr.URL = ss;
        }  
      }  
    }  
  }

  // -- Method: Index(keyword) --
  function DoIndexCmd() {
    if (IsConnected() == 1) 
      H2ViewerSvr.Index(document.all.ID_IndexKeyword.value);
  }  

  // -- Method: Search(str) --
  function DoSearchCmd() {
    if (IsConnected() == 1) 
      H2ViewerSvr.Search(document.all.ID_SearchStr.value);
  }  
    
  // -- Method: PageTab(PageNum) --
  function DoPageTabCmd() {
    if (IsConnected() == 1) 
      H2ViewerSvr.PageTab(document.all.ID_PageTab.value);
  }  
    

</script>

</head>
<body>

<form name="form1">
  <h1>H2Viewer - COM Interface</h1>

  <p>15-Jun-2003 -  V1.1 - added: <a href="#index">Index()</a>, 
  <a href="#search">Search()</a>, <a href="#pagetab">PageTab()</a><br>
  10-Jul-2004 - V1.3.4 - <a href="#SafeConnect">Safe Connect</a></p>

  <table border="1" cellspacing="4" width="100%" id="AutoNumber1" style="border-width: 1; " cellpadding="4" bordercolorlight="#808080" bordercolordark="#000000" bgcolor="#EEEEEE">
    <tr>
      <td width="27%" align="left" valign="top">
      <input type="button" value="Connect to Server" OnClick="ConnectToH2Viewer()"><p>
      
      <!-- Reloading the page is will disconnect the server. Setting the ServerObj to null should work but does not in MS JScript -->
      <input type="button" value="Disconnect" OnClick="JavaScript:window.location = window.location"></p></td>
      
      <td width="73%" align="left" valign="top">Connect to the ActiveX COM 
      server using either:<br>
      <b>ProgrID = &quot;H2Viewer.h2vmain&quot;<br>
      CLASSID=&quot;CLSID:C13B8DA2-8149-45BA-9EEA-5FE23B302E76&quot; </b> 
      <p>The H2Viewer.EXE application will open as soon as you connect. If the 
      application detects that it has been opened via it's COM interface it will 
      open with the main window hidden. In this case you must next call 
      ShowWindow = 1 to show the window.  
      <p>As soon as you disconnect the server (by destroying the Object in code. 
      EG. Obj out of scope or set to null) 
      the window will close (unless of course the window was already open before 
      you connected).<p><b><a name="SafeConnect">10-Jul-2004: Save Connect</a></b><p>When calling ShowWindow=1 immediately after 
      connecting to the COM server (above) you can get an exception error. This 
      is a timing problem where the main window is not yet initialized. The 
      fix is as follows: <br>
      a) Get h2Viewer version 1.3.4 or greater<br>
      b) Immediately after connecting, loop until WindowHandle != 0<br>
      <br>
      <b>Example:</b>&nbsp; The &quot;Connect to Server&quot; button (above) now runs the 
      following code if connection is successful:<i><br>
      </i>&nbsp;&nbsp; <i>&nbsp;do {} while 
      (H2ViewerSvr.WindowHandle == 0);</i><p>
      <input type="button" value="Connect &amp; ShowWindow" OnClick="ConnectToH2ViewerAndShow()"></td>
    </tr>
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="ShowWindow = 1" OnClick="ShowWindow(1)"> 
      <input type="button" value="ShowWindow = 0" OnClick="ShowWindow(0)"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Property: <b>ShowWindow</b> 
      [Integer, Write Only]<p>Set ShowWindow=1 to show the main window.<br>
      Set ShowWindow=0 to hide the main window.</td>
    </tr>
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="Close()" OnClick="CloseH2Viewer()"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Method:<b> 
      Close()</b><p>Close the application</td>
    </tr>
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="Version" OnClick="GetVersion()"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Property: <b>Version</b> [String, Read 
      Only]<p>Returns the application Version number as a string <br>
      in the form: &quot;MajorVer.MinorVer.ReleaseNo.BuildNo&quot;</td>
    </tr>
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="Version" OnClick="GetVersionNos()"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Property:<b> 
      V1</b> [Integer, Read Only]<br>
      Property: <b>V2</b> [Integer, Read Only]<br>
      Property: <b>V3 </b>[Integer, Read Only]<br>
      Property: <b>V4 </b>[Integer, Read Only]<p>Returns the individual 
      application Version numbers as <br>
      MajorVer, MinorVer, ReleaseNo, BuildNo</td>
    </tr>
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="WindowHandle" OnClick="GetWindowHandle()"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Property:<b> 
      WindowHandle</b> [Integer, Read Only]<p>Returns the handle of the main 
      window.</td>
    </tr>
    
    
    
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="Open(URL, Filter)" OnClick="DoOpenURLFilter()"><p>URL 
      (Param1):<br>
      <input type="text" name="ID_OpenURL" size="34" value="ms-help://MS.VSCC"></p>
      <p>FilterName (Param2):<br>
      <input type="text" name="ID_OpenFilterName" size="34" value="Visual C#"><p>FilterQuery (Param3):<br>
      <input type="text" name="ID_OpenFilterQuery" size="34"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Method: <b>
      Open(URL, FilterName, FilterQuery)</b><p>Opens a collection in the viewer.</p>
      <p><b>URL [IN]: </b>Namespace or HxS file to open in the viewer.<br>
      Example1: &quot;ms-help://MS.VSCC&quot; or just &quot;MS MS.VSCC&quot; (we add the ms-help:// 
      prefix for you). Opens the MS MS.VSCC collection.<br>
      Example2: &quot;ms-help://MS.VSCC/vsccCommon/html/vsccCommon_Start_Page.htm&quot;
      <br>
      Opens the MS MS.VSCC collection at a given path.<br>
      Example3: &quot;c:\path\myhelp.hxS&quot; - If the full path to a .HxS file is 
      provided then we create a temporary namespace so the help file can be 
      viewed.</p>
      <p><b>FilterName [IN]:</b> Name of the Filter to select from the Filter 
      drop down or '' (an empty string).
      The filter name must be defined in the current collection and must have a 
      valid Filter Query string associated with it. If invalid then we open with 
      no filter applied.<p><b>FilterQuery [IN]:</b> Filter Query string to use when opening 
      collection or '' (an empty string).
      <p>Normally you would not specify both a FilterName and FilterQuery at the 
      same time. Have one or the other or none. When not used set to empty 
      string.</td>
    </tr>
    
    
    
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="Set URL" OnClick="SetURL()"><input type="button" value="Get URL" OnClick="GetURL()"><p>
      URL:<br>
      <input type="text" name="ID_URLCtrl" size="34" value="ms-help://MS.VSCC/vsccCommon/html/vsccCommon_Start_Page.htm"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Property:<b> 
      URL</b> [String, Read/Write]<p>Use URL to Set or Get the browsers URL. 
      Anything that can be entered into the Internet Explorer URL address line 
      is appropriate here. When setting URL= we also auto-sync the Table Of 
      Contents control if the item exists in the TOC.</td>
    </tr>
    
    
    
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="CurrentNS" OnClick="GetCurrentNS()"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Property: <b>
      CurrentNS</b> [String, Read Only]<p>Returns the Current namespace name.
      <br>
      EG. If ms-help://MS.VSCC is loaded the CurrentNS returns MS.VSCC</td>
    </tr>
    
    
    
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="Set FilterName" OnClick="SetFilterName()"><br>
      <input type="button" value="Get FilterName" OnClick="GetFilterName()"><p>FilterName (Param2):<br>
      <input type="text" name="ID_FilterName" size="34" value="Visual C#"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Property <b>
      FilterName</b> [String, Read Only]<p>Use FilterName to Set or Get the 
      Current Filter name for the current collection. Setting Filtername=&quot;XYZ&quot; will 
      have no effect if the current collection does not contain a filter &quot;XYZ&quot; 
      or no collection is opened. 
      Set Filter=&quot;&quot; (empty string) to set Filtering Off for the 
      current collection. If (GET) Filter returns an 
      empty string  then no filter is currently set for the current 
      collection.</td>
    </tr>
    
    
    
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="Set FilterQuery" OnClick="SetFilterQuery()"><br>
      <input type="button" value="Get FilterQuery" OnClick="GetFilterQuery()"><p>
      FilterQuery (Param2):<br>
      <input type="text" name="ID_FilterQuery" size="34" value="&quot;DocSet&quot; = &quot;C#&quot; OR (&quot;DocSet&quot; = &quot;MSDN&quot; AND &quot;ProductVers&quot; = &quot;C#&quot;)"></td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Property <b>
      FilterQuery</b> [String, Read Only]<p>Similar to FilterName above but 
      instead of referencing the Query string indirectly via the associated 
      QueryName you can Set or Get the Filter Query string directly. This string 
      can be any valid query string (as you would define one in the Filter Edit 
      dialog).</td>
    </tr>
    
    
    
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="QueryForURL(p1,p2,p3)" OnClick="DoQueryForURL()"><p>
      Namespace 
      (Param1):<br>
      <input type="text" name="ID_QueryP1" size="34" value="MS.VSCC"></p>
      <p>
      Search Term 
      (Param2):<br>
      <input type="text" name="ID_QueryP2" size="34" value="HomePage"></p>
      <p>NavDataMoniker (Param3):<br>
      <select size="1" name="ID_QueryP3">
      <option value="!DefaultKeywordIndex">!DefaultKeywordIndex</option>
      <option value="!DefaultAssociativeIndex">!DefaultAssociativeIndex</option>
      <option value="!DefaultNamedURLIndex" selected>!DefaultNamedURLIndex</option>
      <option value="!DefaultFullTextSearch">!DefaultFullTextSearch</option>
      <option value="!DefaultContextWindowIndex">!DefaultContextWindowIndex</option>
      <option value="!SampleInfo">!SampleInfo</option>
      <option value="!DefaultToc">!DefaultToc</option>       
      </select><p>
      FilterQuery 
      (Param4) (*=current):<br>
      <input type="text" name="ID_QueryP4" size="34"></p>
      <p>
      Options 
      (Param5):<br>
      <input type="text" name="ID_QueryP5" size="34" value="0"></p>
      </td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">Method: <b>
      QueryForURL(Namespace, SearchTerm, NavDataMoniker, FilterQuery, Options): String</b><p>
      Performs a query on the current Collection and returns a string that 
      contains the URL of the first topic in the results list. The query can be 
      based on an index, full-text search, attribute, or context identifier.</p>
      <p>
      The QueryForURL returns an empty string if </p>
      <ul>
        <li>The Namespace provided is invalid.</li>
        <li>No Namespace is provided and there is no Namespace currently loaded 
        in the editor.</li>
        <li>The query produces zero results.</li>
      </ul>
      <p>
      <b>Namespace [IN]:</b> Namespace to perform query on.<br>
      Set this to an empty string to search the currently opened collection.<br>
      Set to a valid Namespace name (EG. MS.VSCC) to create a new temporary 
      Session and search that. If an invalid NS is used then search result will 
      be empty string.</p>
      <p><b>SearchTerm [IN]:</b> Text to search for.</p>
      <p><b>NavDataMoniker [IN]: </b>Moniker specifies which part of the 
      collection to search:<br>
      !DefaultKeywordIndex -- Default keyword index (KLinks).<br>
      !DefaultAssociativeIndex -- Default associative index (ALinks).<br>
      !DefaultNamedURLIndex -- Named URLs Index (HomePage, DefaultPage etc)<br>
      !DefaultFullTextSearch -- Full-text search index.<br>
      !DefaultContextWindowIndex -- Default context window index, if one exists.<br>
      !SampleInfo -- Performs a query on the Sample Index.<br>
      !DefaultToc -- Performs a query on the Default TOC.</p>
      <p><b>FilterQuery [IN]:</b> Restrict the scope of the Query by defining a 
      Filter Query String. Set to an empty string to use no filtering in the 
      query.<br>
      EG. &quot;DocSet&quot; = &quot;C#&quot; OR (&quot;DocSet&quot; = &quot;MSDN&quot; AND &quot;ProductVers&quot; = &quot;C#&quot;)<br>
      Note: If Namespace is not specified then you can set FilterQuery=&quot;*&quot; 
      (character *) to mean use the current filter query.<p>
      <b>Options [IN]:</b> Integer value, Normally set to <b>0</b> (zero).<br>
      <b>0</b> -- No Options,<br>
      <b>1</b> -- For FullTextSearch. Restricts search to topic titles.<br>
      <b>2</b> -- For FullTextSearch. Enable Stemming. Enables run-time 
      stemming, for example, a search on &quot;print&quot; would also return &quot;printing,&quot; 
      &quot;printed,&quot; &quot;prints,&quot; and so on.<br>
      <b>3</b> -- For FullTextSearch. Search Previous Results. Searches previous 
      results.<br>
      <b>10</b> -- For KeywordSearch. Causes a keyword search to be case 
      sensitive<br>
&nbsp;</td>
    </tr>
    

    
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="Index(Keyword)" OnClick="DoIndexCmd()"><p>
      Keyword:<br>
      <input type="text" name="ID_IndexKeyword" size="34" value="Open"></p>
      </td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">
      <a name="index">Method: <b>
      Index(Keyword)</b></a><p>Equivalent to selecting the Index navigation page, 
      typing in a <i>Keyword</i> and pressing Enter.</p>
      <p><b>Keyword [IN]: </b>Keyword (K Index) or partial keyword to 
      search for.</p>
      </td>
    </tr>
    
    
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="Search(Keyword)" OnClick="DoSearchCmd()"><p>
      Search String:<br>
      <input type="text" name="ID_SearchStr" size="34" value="Open"></p>
      </td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">
      <a name="search">Method: <b>
      Search(SearchStr)</b></a><p>Equivalent to selecting the Search navigation page, 
      typing in a <i>SearchStr</i> and pressing Enter.</p>
      <p><b>SearchStr [IN]:</b> Text string to search for.</p>
      </td>
    </tr>
    
    
    <tr>
      <td width="27%" align="left" valign="top" bgcolor="#FFFFCC">
      <input type="button" value="PageTab(PageNum)" OnClick="DoPageTabCmd()"><p>
      Page# (must be 1, 2, 3 or 4):<br>
      <input type="text" name="ID_PageTab" size="34" value="2"></p>
      </td>
      <td width="73%" align="left" valign="top" bgcolor="#FFFFCC">
      <a name="pagetab">Method: <b>
      PageTab(PageNum)</b></a><p>Equivalent to selecting a navigation page tab.</p>
      <p><b>PageNum [IN]:</b> Navigation Page to select.<br>
      1=Contents, 2=Index, 3=Search, 4=Favs<br>
      Example: PageTab(2) = Selects Index Page</p>
      </td>
    </tr>
    
    
    
  </table>
  
  <p>&nbsp;</p>
</form>


</body>
</html>